﻿using RdpClient.BLL;
using Common.Class;
using SyncFileCommon.BLL;

namespace RdpClient.Forms
{
    public partial class FrmOption : Form
    {
        public FrmOption()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;
            this.FormBorderStyle = FormBorderStyle.FixedDialog;//设置边框为不可调节
            this.MaximizeBox = false; //取消最大化按键
            this.MinimizeBox = false; //取消最小化按键
            this.ShowInTaskbar = false;//不在任务栏显示多个窗体框

        }



        private void FrmOption_Load(object sender, EventArgs e)
        {
            txtLoginPassword.Text = "jlsoftdefultpassword";
            txtLoginPassword.PasswordChar = '*';

            txtServerURL.Text = EncryptHelper.DecryptString_Aes(ConfigBLL.ServiceConfig.ServiceURL, "JlPwd");  
            txtServerPublicKey.Text = EncryptHelper.DecryptString_Aes(ConfigBLL.ServiceConfig.ServicePublicKey, "JlPwd"); 
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private void btnSystem_Click(object sender, EventArgs e)
        {
            pnlCenter.AutoScrollPosition = new Point(0, -1 * pnlCenter.AutoScrollPosition.Y + pnlSystem.Top);

            pnlCenter.Refresh();
            pnlCenter.Invalidate();
            pnlCenter.Update();
        }

        private void btnServer_Click(object sender, EventArgs e)
        {
            pnlCenter.AutoScrollPosition = new Point(0, -1 * pnlCenter.AutoScrollPosition.Y + pnlServer.Top);

            pnlCenter.Refresh();
            pnlCenter.Invalidate();
            pnlCenter.Update();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (txtLoginPassword.Text.Trim() == "")
            {
                SessionBLL.LoginPassword = "";
            }
            else
            {
                if (txtLoginPassword.Text.Trim() != "jlsoftdefultpassword")
                {
                    SessionBLL.LoginPassword = EncryptHelper.EncryptString_Aes(txtLoginPassword.Text.Trim(), "JlPwd");
                }
            }
            SessionBLL.SessionListSave(SessionBLL.SessionList);

            if (txtServerURL.Text.Trim() != "")
            {
                ConfigBLL.ServiceConfig.ServiceURL = EncryptHelper.EncryptString_Aes(txtServerURL.Text.Trim(), "JlPwd");  

                if (txtServerPublicKey.Text.Trim() != "")
                {
                    ConfigBLL.ServiceConfig.ServicePublicKey = EncryptHelper.EncryptString_Aes(txtServerPublicKey.Text.Trim(), "JlPwd");  
                }

                ConfigBLL.SaveConfig(); 
            }

            this.DialogResult = DialogResult.OK;
        }
    }
}
